<?php
class Gosc extends My_Model_Abstract {

	protected $sEmail;
	protected $sRola;
	
	public function getEmail() {
		return $this->sEmail;
	}
	
	public function getRole() {
		return $this->sRola;
	}
	
	public function __construct() {
		$this->sEmail = 'niezalogowany';
		$this->sRola = 'guest';
	}
	
	public function login($sEmail, $sHaslo) {
		$oDb = My_Db::factory('db_Uzytkownik');

		$sQuery = $oDb->select()->where('email = ?', $sEmail)->where('haslo = ?', sha1($sHaslo))->where('usuniety = ?', 0);

		$oRow = $oDb->fetchRow($sQuery);
		
		if($oRow != null) {
			$oSesja = new Zend_Session_Namespace( 'zalogowanyUzytkownik' );
			$oSesja->unlock();
			$oSesja->oUzytkownik = new Uzytkownik($oRow->id_uzytkownika);
			$oSesja->lock();
			return true;
		} else
			return false;
	}	
}
?>